package br.com.arosa.dao;

import java.util.*;
import java.sql.*;
import br.com.easynet.database.DataSet;
import br.com.jdragon.dao.*;
import br.com.arosa.transfer.*;

public class Tb_funcionarioDAO extends ObjectDAO { 
	 public Tb_funcionarioDAO(DAOFactory dao) throws Exception {
		 setDAOFactory(dao);
 		 con = dao.create();
 	 }

	 public void insert(Tb_funcionarioT tb_funcionarioT ) throws Exception { 
		 PreparedStatement pStmt=null;
		 try {
			 String sql = "insert into tb_funcionario  ( id_funcionario, id_perfil, nome, login, senha, telefone, comissao) values ( ? , ? , ? , ? , ? , ? , ? )";
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_funcionarioT.getId_funcionario());
			 pStmt.setObject(2, tb_funcionarioT.getId_perfil());
			 pStmt.setObject(3, tb_funcionarioT.getNome());
			 pStmt.setObject(4, tb_funcionarioT.getLogin());
			 pStmt.setObject(5, tb_funcionarioT.getSenha());
			 pStmt.setObject(6, tb_funcionarioT.getTelefone());
			 pStmt.setObject(7, tb_funcionarioT.getComissao());
			 pStmt.execute();
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { 
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public void update(Tb_funcionarioT tb_funcionarioT ) throws Exception { 
		 PreparedStatement pStmt=null;
		 try {
			 String sql = "update tb_funcionario set  id_perfil=?, nome=?, login=?, senha=?, telefone=?, comissao=?  where  id_funcionario=?";
 			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_funcionarioT.getId_perfil());
			 pStmt.setObject(2, tb_funcionarioT.getNome());
			 pStmt.setObject(3, tb_funcionarioT.getLogin());
			 pStmt.setObject(4, tb_funcionarioT.getSenha());
			 pStmt.setObject(5, tb_funcionarioT.getTelefone());
			 pStmt.setObject(6, tb_funcionarioT.getComissao());
			 pStmt.setObject(7, tb_funcionarioT.getId_funcionario());
			 pStmt.execute();
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { 
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public void delete(Tb_funcionarioT tb_funcionarioT ) throws Exception { 
		 PreparedStatement pStmt=null;
		 try {
			 String sql = "delete from tb_funcionario where  id_funcionario=?";
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_funcionarioT.getId_funcionario());
			 pStmt.execute();
		 } catch (Exception e)  {
 			  throw e;
 		} finally {
 			 try { 
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 private List<Tb_funcionarioT> resultSetToObjectTransfer(ResultSet rs) throws Exception { 
		 List<Tb_funcionarioT> objs = new Vector();
		 while (rs.next()) { 
 			 Tb_funcionarioT tb_funcionarioT = new Tb_funcionarioT();
			 tb_funcionarioT.setId_funcionario(rs.getInt("id_funcionario"));
			 tb_funcionarioT.setId_perfil(rs.getInt("id_perfil"));
			 tb_funcionarioT.setNome(rs.getString("nome"));
			 tb_funcionarioT.setLogin(rs.getString("login"));
			 tb_funcionarioT.setSenha(rs.getString("senha"));
			 tb_funcionarioT.setTelefone(rs.getString("telefone"));
			 tb_funcionarioT.setComissao(rs.getDouble("comissao"));
			 objs.add(tb_funcionarioT);
 		 }
 		 return objs; 
 	 }
	 public List<Tb_funcionarioT> getAll() throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_funcionario"; 
			 pStmt = con.prepareStatement(sql);
			 rs = pStmt.executeQuery();
 			 List<Tb_funcionarioT> list = resultSetToObjectTransfer(rs);
 			 return list; 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_funcionarioT> getById(Tb_funcionarioT tb_funcionarioT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_funcionario where  id_funcionario=?"; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_funcionarioT.getId_funcionario());
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_funcionarioT> getById_funcionario(Tb_funcionarioT tb_funcionarioT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_funcionario where  id_funcionario = ? "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_funcionarioT.getId_funcionario());
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_funcionarioT> getById_perfil(Tb_funcionarioT tb_funcionarioT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_funcionario where  id_perfil = ? "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_funcionarioT.getId_perfil());
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_funcionarioT> getByNome(Tb_funcionarioT tb_funcionarioT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_funcionario where  Upper(nome) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_funcionarioT.getNome()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_funcionarioT> getByLogin(Tb_funcionarioT tb_funcionarioT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_funcionario where  Upper(login) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_funcionarioT.getLogin()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_funcionarioT> getBySenha(Tb_funcionarioT tb_funcionarioT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_funcionario where  Upper(senha) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_funcionarioT.getSenha()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_funcionarioT> getByTelefone(Tb_funcionarioT tb_funcionarioT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_funcionario where  Upper(telefone) like Upper(?) "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, '%' + tb_funcionarioT.getTelefone()+'%' );
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 	 public List<Tb_funcionarioT> getByComissao(Tb_funcionarioT tb_funcionarioT) throws Exception { 
		 PreparedStatement pStmt=null;
		 ResultSet rs=null;
		 try {
			 String sql = "select * from tb_funcionario where  comissao = ? "; 
			 pStmt = con.prepareStatement(sql);
			 pStmt.setObject(1, tb_funcionarioT.getComissao());
			 rs = pStmt.executeQuery();
 			 return resultSetToObjectTransfer(rs); 
 		 } catch (Exception e) {
 			  throw e;
 		} finally {
 			 try { rs.close();
 			 pStmt.close();} catch (Exception e) {}
 			  
 		} 
 	} 

 

 }